<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.acwing.com/static/jquery/js/jquery-3.3.1.min.js"></script><!--jquery链接-->
    <link href="/css/registerOj.css" rel="stylesheet" type="text/css"/>
    <script type="module" src="/js/textBoxAutoHeight.js"></script><!--此文件用来使得textarea自动调节它的高度-->
    <script type="module" src="/js/changeAndBan_tab_.js"></script><!--此js文件是用来ban掉并且修改tab键的一些不便的功能-->
</head>
<body>
<div class="nav">
    <ul class="menu">
        <li class="lli"><a href="#" title="首页" target="_self">首页</a></li>
        <li class="lli"><a href="#" title="项目" target="_blank">题库</a></li>
        <li class="lli"><a href="#" title="论坛" target="_blank">论坛</a></li>
        <li class="btn"><input id="search" type="search" placeholder="Search..." autofocus required/>
            <button type="submit">Go</button>
        </li><!--搜索框-->
        <li class="image">
            <img src="/imgs/225默认头像(1).png" height="30px" alt=""/> | 用户名 &emsp;&emsp;
            <a href="#">登录 | 注册</a>
        </li>

    </ul>
</div>
<br><br><br><br><br>
<div class="container"><!--表格部分-->
    <br>
    <h3>题目标题</h3><br>
    <textarea id="QesName" class="pi" style="background-color:#F8F8F8;"></textarea><br>
    <br>
    <h3>难易程度</h3><br>
    <textarea id="QesLevel" class="pi" style="background-color:#F8F8F8;"></textarea><br>
    <br>
    <h3>题目描述</h3><br>
    <textarea id="QesDes" class="pi" style="background-color:#F8F8F8;"></textarea><br>
    <h3>测试样例</h3><br>
    <textarea id="QesExample" class="pi" style="background-color:#F8F8F8;"></textarea><br>
    <br><br>
    <h3>模板代码</h3><br>
    <form style="height: 400px;">
        <div class="mian">
            <!--
                        <div class="leftBox"><textarea wrap="off" cols="2" class="leftNum" disabled></textarea></div>
            -->
            <textarea id="QesTemplate" class="test" name="content" onkeyup="keyUp()"
                      onscroll="getId('leftNum').scrollTop = this.scrollTop;">
    </textarea>
        </div>
        <br>
        <!-- <button type="submit"
                 style="background-color:deepskyblue;color: white; height: 30px; width: 70px; border-radius: 6px; border-style: none; cursor: pointer; ">
             提交
         </button>-->
    </form>
    <br><br><br>
    <h3>测试代码</h3><br>
    <form style="height: 400px;">
        <div class="mian">

            <!--            <div class="leftBox"><textarea wrap="off" cols="2" class="leftNum" disabled></textarea></div>-->

            <textarea id="QesTestcode" class="test" name="content" onkeyup="keyUp()"
                      onscroll="getId('leftNum').scrollTop = this.scrollTop;">
    </textarea>
        </div>
        <br>
        <button onclick="registerOj()" type="button"
                style="background-color: deepskyblue; color: white; height: 30px; width: 70px; border-radius: 6px; border-style: none; cursor: pointer; ">
            提交
        </button>
    </form>
    <br><br>


</div>

<!--导入axios文件-->
<script src="/js/axios-0.18.0.js"></script>

<script type="text/javascript"> //滚动条设置 目前已经删除了 没啥用
var num = "";
var test = getId('test');

function getId(obj) {
    return document.getElementsByClassName(obj);
}

function keyUp() {/*按键被释放时触发*/
    var str = test.value;
    str = str.replace(/\r/gi, "");
    str = str.split("\n");
    var n = str.length;
    line(n);
}

function line(n) {
    var lineobj = getId("leftNum");
    for (var i = 1; i <= n; i++) {
        if (document.all) {
            num += i + "\r\n";//判断浏览器是否是IE
        } else {
            num += i + "\n";
        }
    }
    lineobj.value = num;
    num = "";
}

(function () {
    keyUp();
})();
</script>

<script>
    window.onload = function () { //页面加载时初始化文本框中的数据
        document.getElementById("QesTemplate").value = "";
        document.getElementById("QesTestcode").value = "";
        document.getElementById("QesTemplate").value = "public class Solution {\n" +
            "    public 返回类型 方法名称(参数...) {\n" +
            "        \n" +
            "    }\n" +
            "}";
        document.getElementById("QesTestcode").value = "public static void main(String[] args) {\n" +
            "    Solution solution = new Solution();\n" +
            "    int a = solution.方法名称(参数...);\n" +
            "    if (a != 正确答案) {\n" +
            "        System.out.println(\"1\");\n" +
            "        return;\n" +
            "    }\n" +
            "    int b = solution.方法名称(参数...);\n" +
            "    if (b != 正确答案) {\n" +
            "        System.out.println(\"2\");\n" +
            "        return;\n" +
            "    }\n" +
            "    System.out.println(\"0\");\n" +
            "}";
    }

    function registerOj() {
        //获取输入
        let title = encodeURIComponent(document.getElementById("QesName").value);
        let level = encodeURIComponent(document.getElementById("QesLevel").value);
        let description = encodeURIComponent(document.getElementById("QesDes").value);
        let example = encodeURIComponent(document.getElementById("QesExample").value);
        let template = encodeURIComponent(document.getElementById("QesTemplate").value);
        let test = encodeURIComponent(document.getElementById("QesTestcode").value);
        //检查是否为空 对用户做出提醒
        if (title == "") {
            alert("请输入题目标题");
        } else if (level == "") {
            alert("请输入难易程度");
        } else if (description == "") {
            alert("请输入题目描述");
        } else if (example == "") {
            alert("请输入题目样例");
        } else if (template == "") {
            alert("请输入模板代码");
        } else if (test == "") {
            alert("请输入测试代码");
        } else {
            //确定所有输入非空后 提醒用户是否确认提交
            let flag = confirm("确认提交");
            if (flag) {
                //确认提交
                axios({
                    method: "post",
                    url: "http://localhost:8080/addJava",
                    data: "title=" + title + "&" + "level=" + level + "&" + "description=" + description + "&" + "template=" + template + "&" + "test=" + test + "&example=" + example
                }).then(function (resp) {
                    let res = resp.data.data;
                    alert(res);
                })
            }
        }

    }
</script>

</body>
</html>